# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class Fm2Pipeline:
    def process_item(self, item, spider):
        # 提取类型
        msg_type = item.get("type")

        if msg_type == "img":
            print("正在保存到图片文件...")
            # 如果item中存储的是图片的二进制等数据的话，应该创建一个文件
            # 然后将二进制输入写入到文件，即可完成图片保存
            with open(item.get("img_name"), "wb") as f:
                f.write(item.get("img_bytes"))
        elif msg_type == "info":
            # 可以将30条信息存储到CSV文件
            print("正在存储到文件....")
